package com.jackrain.nea.fc.ps.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * “条码档案接口” FC-->货品网站
 * Mapper
 *
 * @author WSL
 * @create 2018/1/19
 */
@Mapper
public interface ViewCskuQueryMapper {

    class SelectSku
    {
        public String selectSku(Map map)
        {
            return new SQL()
            {
                {
                    SELECT("CP_C_DISTRIB_ID,ECODE,PS_C_PRO_ID,PS_C_SPEC1OBJ_ID,PS_C_SPEC2OBJ_ID,STOPREPLEN");
                    FROM("PS_C_SKU");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length()-1).append(")");
                    WHERE("ID IN "+sb.toString());
                    WHERE("CP_C_DISTRIB_ID<>0");
                }
            } .toString();
        }
    }

    /**
     * 根据param查询条件 查询【人员档案】表
     * @param param
     * @return String
     */
    @SelectProvider(type = SelectSku.class, method = "selectSku")
    List<HashMap> selectSku(@Param("list") Object[] param);

    /**
     * 配销中心 外键关联查询表【CP_C_STOREORG】的ECODE
     * @param distribId
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_STOREORG WHERE ID = #{distribId}")
    String getDistribEcode(Long distribId);

    /**
     * 款号 外键关联查询表【PS_C_PRO】的ECODE
     * @param proId
     * @return
     */
    @Select("SELECT ECODE FROM PS_C_PRO WHERE ID = #{proId}")
    String getProEcode(Long proId);

    /**
     * 颜色、尺寸编号 外键关联查询表【PS_C_SPECOBJ】的ECODE
     * @param specobjId
     * @return
     */
    @Select("SELECT ECODE FROM PS_C_SPECOBJ WHERE ID = #{specobjId}")
    String getSpecobjEcode(Long specobjId);

}
